from .. import models
import json
from automationreport import global_configure


class UpdateData:

    # 更新测试用例数据
    def update_case_count(self):
        app_count = len(models.automation_function_app.objects.all())
        web_count = len(models.automation_function_web.objects.all())
        interface_count = len(models.automation_interface.objects.all())
        all_count = app_count + web_count + interface_count
        connect_redis = global_configure.ConfigureFile().get_configure_file('redis', '')
        connect_redis.set('app_count', json.dumps({"code": "200", "msg": "succes", "data": {'casecount': app_count}}))
        connect_redis.set('web_count', json.dumps({"code": "200", "msg": "succes", "data": {'casecount': web_count}}))
        connect_redis.set('interface_count', json.dumps({"code": "200", "msg": "succes", "data": {'casecount': interface_count}}))
        connect_redis.set('all_count', json.dumps({"code": "200", "msg": "succes", "data": {'casecount': all_count}}))
        return [app_count, web_count, interface_count, all_count]
